package com.zmovie.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmovie.framework.domain.User;
import com.zmovie.framework.service.UserService;
import com.zmovie.framework.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lenovo
* @description 针对表【user】的数据库操作Service实现
* @createDate 2023-11-27 16:07:45
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public User checkLogin(String username, String password) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername, username);
        wrapper.eq(User::getPassword, password);
        return getOne(wrapper);
    }

    @Override
    public List<User> listCinemaAdmin() {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getRoleId, 2);
        wrapper.orderByAsc(User::getUsername);
        return list(wrapper);
    }

    @Override
    public Page<User> pageUser(Integer pageNo, Integer pageSize, User user) {
        Page<User> userPage = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        //用户名
        wrapper.like(user.getUsername() != null, User::getUsername, user.getUsername());
        //手机号
        wrapper.like(user.getPhone() != null, User::getPhone, user.getPhone());
        //邮箱
        wrapper.like(user.getEmail() != null, User::getEmail, user.getEmail());
        //性别
        wrapper.eq(user.getGender() != null, User::getGender, user.getGender());
        wrapper.orderByAsc(User::getId);
        return page(userPage, wrapper);
    }
}




